﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using HZH_Controls.Forms;

namespace HangzhouChipProject
{
    public partial class frm_Gohome : FrmWithOKCancel1
    {
        mc.THomePrm homePrm1;
        mc.THomePrm homePrm2;
        mc.THomePrm homePrm3;
        mc.THomePrm homePrm4;
        mc.THomePrm homePrm5;
        mc.THomePrm homePrm6;
        mc.THomePrm homePrm7;
        mc.THomePrm homePrm8;
        mc.THomeStatus homeStatus;
        const short CORE = 1;  //板卡
        short Axis;
        public frm_Gohome()
        {
            InitializeComponent();
            this.Title = "回原点";
            this.IsShowCloseBtn = true;
            this.BackColor = Color.FromArgb(128, 128, 255);
        }
        protected override void OnLoad(EventArgs e)
        {
            this.Axis_Combox.SelectedIndex = 0;
        }
         
        private void ucBtnExt_goHome_BtnClick(object sender, EventArgs e)
        {
            uiDataToPrm();
            Task Taskgohome = new Task(()=> {
                PrintfLog("启动运动");
                if (MotorsControl.MonitorGoHome(CORE, Axis, homePrm1, homeStatus) == -6)
                {
                    PrintfLog("打开控制器失败");
                };
            });
            
            Taskgohome.Start();


        }
        private void uiDataToPrm()
        {
            homePrm1.mode = 13;
            Axis =short.Parse( this.Axis_Combox.SelectedItem.ToString());
            homePrm1.acc =Convert.ToDouble( this.textBox_acc.Text);
            homePrm1.dec= Convert.ToDouble(this.textBox_velHigh.Text);
            homePrm1.velHigh= Convert.ToDouble(this.textBox_velHigh.Text);
            homePrm1.velLow = Convert.ToDouble(this.textBox_velLow.Text);
            homePrm1.smoothTime=short.Parse(this.textBox_Smooth.Text);
            homePrm1.searchHomeDistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
            homePrm1.searchIndexDistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
            homePrm1.moveDir = short.Parse(ucRadioButton_Gozera0Po.Checked == true ? "1" : "0");
            homePrm1.indexDir = short.Parse(ucRadioButton_IndexPo.Checked == true ? "1" : "0");
            homePrm1.triggerIndex = short.Parse(ucRadioButton_Triggerindexpo.Checked == true ? "1" : "0");
            homePrm1.homeOffset = Convert.ToInt32(Zero_Offset_tb.Text.ToString());
        }
        private void PrintfLog(string slog)
        {
            try
            {
                PrintLog_TB.Invoke(new Action(() =>
                {
                    PrintLog_TB.AppendText(string.Format("消息提示: {0},{1},{2}", DateTime.Now.ToString(), slog, Environment.NewLine));
                }));
            }
            catch (Exception er) { }
        }
              
        private void ucBtnExt_Stop_BtnClick(object sender, EventArgs e)
        {
            MotorsControl.MotorStop(CORE, Axis);
            PrintfLog("暂停运动");
        }

        private void ucBtnExt_allGohomeAxis_BtnClick(object sender, EventArgs e)
        {
            backHome();
        }

        private void ucBtnExt_SaveParamer_BtnClick(object sender, EventArgs e)
        {
            int axis = Convert.ToInt16( this.Axis_Combox.SelectedItem.ToString()) ;
           // InterLayer.SavaDataParamer(Properties.Axis1.Default);
            SaveUiDataToSetting(axis);
            PrintfLog("参数保存成功 "+axis);
        }
        #region 读取参数倒UI界面
       
        private void readDataToUI(int i)
        {
            try
            {

                switch (i)
                {
                    case 1:
                        readdatatoUI1();
                        break;
                    case 2:
                        readdatatoUI2();
                        break;
                    case 3:
                        readdatatoUI3();
                        break;
                    case 4:
                        readdatatoUI4();
                        break;
                    case 5:
                        readdatatoUI5();
                        break;
                    case 6:
                        readdatatoUI6();
                        break;
                    case 7:
                        readdatatoUI7();
                        break;
                    case 8:
                        readdatatoUI8();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {


            }
        }
        private void readdatatoUI1()
        {
            this.textBox_velHigh.Text = Properties.Axis1.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis1.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis1.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis1.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis1.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis1.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis1.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis1.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI2()
        {
            this.textBox_velHigh.Text = Properties.Axis2.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis2.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis2.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis2.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis2.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis2.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis2.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis2.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI3()
        {
            this.textBox_velHigh.Text = Properties.Axis3.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis3.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis3.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis3.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis3.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis3.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis3.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis3.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI4()
        {
            this.textBox_velHigh.Text = Properties.Axis4.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis4.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis4.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis4.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis4.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis4.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis4.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis4.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI5()
        {
            this.textBox_velHigh.Text = Properties.Axis5.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis5.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis5.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis5.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis5.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis5.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis5.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis5.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI6()
        {
            this.textBox_velHigh.Text = Properties.Axis6.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis6.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis6.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis6.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis6.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis6.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis6.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis6.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI7()
        {
            this.textBox_velHigh.Text = Properties.Axis7.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis7.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis7.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis7.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis7.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis7.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis7.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis7.Default.searchIndexdistance.ToString();
        }
        private void readdatatoUI8()
        {
            this.textBox_velHigh.Text = Properties.Axis8.Default.velHigh.ToString();
            this.textBox_velLow.Text = Properties.Axis8.Default.velLow.ToString();
            this.textBox_acc.Text = Properties.Axis8.Default.acc.ToString();
            this.textBox_dec.Text = Properties.Axis8.Default.dec.ToString();
            this.textBox_Smooth.Text = Properties.Axis8.Default.Smooth.ToString();
            this.Zero_Offset_tb.Text = Properties.Axis8.Default.Offset.ToString();
            this.textBox_searchhomedistance.Text = Properties.Axis8.Default.searchhomedistance.ToString();
            this.textBox_searchIndexdistance.Text = Properties.Axis8.Default.searchIndexdistance.ToString();
        }
        #endregion
        #region 读取回零参数
        private void readDataToParamer(int i)
        {
            try
            {

                switch (i)
                {
                    case 1:
                        readDataToParamer1();
                        break;
                    case 2:
                        readDataToParamer2();
                        break;
                    case 3:
                        readDataToParamer3();
                        break;
                    case 4:
                        readDataToParamer4();
                        break;
                    case 5:
                        readDataToParamer5();
                        break;
                    case 6:
                        readDataToParamer6();
                        break;
                    case 7:
                        readDataToParamer7();
                        break;
                    case 8:
                        readDataToParamer8();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {


            }
        }
     
        private void readDataToParamer8()
        {
            try
            {
                homePrm8.mode = 13;
                homePrm8.acc = Properties.Axis8.Default.acc;
                homePrm8.dec = Properties.Axis8.Default.dec;
                homePrm8.velHigh = Properties.Axis8.Default.velHigh;
                homePrm8.velLow = Properties.Axis8.Default.velLow;
                homePrm8.smoothTime = Properties.Axis8.Default.Smooth;
                homePrm8.searchHomeDistance = Properties.Axis8.Default.searchhomedistance;
                homePrm8.searchIndexDistance = Properties.Axis8.Default.searchIndexdistance;
                homePrm8.moveDir = 0;
                homePrm8.indexDir = 1;
                homePrm8.triggerIndex = 1;
                homePrm8.homeOffset = Properties.Axis8.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer7()
        {
            try
            {
                homePrm7.mode = 13;
                homePrm7.acc = Properties.Axis7.Default.acc;
                homePrm7.dec = Properties.Axis7.Default.dec;
                homePrm7.velHigh = Properties.Axis7.Default.velHigh;
                homePrm7.velLow = Properties.Axis7.Default.velLow;
                homePrm7.smoothTime = Properties.Axis7.Default.Smooth;
                homePrm7.searchHomeDistance = Properties.Axis7.Default.searchhomedistance;
                homePrm7.searchIndexDistance = Properties.Axis7.Default.searchIndexdistance;
                homePrm7.moveDir = 0;
                homePrm7.indexDir = 1;
                homePrm7.triggerIndex = 1;
                homePrm7.homeOffset = Properties.Axis7.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer6()
        {
            try
            {
                homePrm6.mode = 13;
                homePrm6.acc = Properties.Axis6.Default.acc;
                homePrm6.dec = Properties.Axis6.Default.dec;
                homePrm6.velHigh = Properties.Axis6.Default.velHigh;
                homePrm6.velLow = Properties.Axis6.Default.velLow;
                homePrm6.smoothTime = Properties.Axis6.Default.Smooth;
                homePrm6.searchHomeDistance = Properties.Axis6.Default.searchhomedistance;
                homePrm6.searchIndexDistance = Properties.Axis6.Default.searchIndexdistance;
                homePrm6.moveDir = 0;
                homePrm6.indexDir = 1;
                homePrm6.triggerIndex = 1;
                homePrm6.homeOffset = Properties.Axis6.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer5()
        {
            try
            {
                homePrm5.mode = 13;
                homePrm5.acc = Properties.Axis5.Default.acc;
                homePrm5.dec = Properties.Axis5.Default.dec;
                homePrm5.velHigh = Properties.Axis5.Default.velHigh;
                homePrm5.velLow = Properties.Axis5.Default.velLow;
                homePrm5.smoothTime = Properties.Axis5.Default.Smooth;
                homePrm5.searchHomeDistance = Properties.Axis5.Default.searchhomedistance;
                homePrm5.searchIndexDistance = Properties.Axis5.Default.searchIndexdistance;
                homePrm5.moveDir = 0;
                homePrm5.indexDir = 1;
                homePrm5.triggerIndex = 1;
                homePrm5.homeOffset = Properties.Axis5.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer4()
        {
            try
            {
                homePrm4.mode = 13;
                homePrm4.acc = Properties.Axis4.Default.acc;
                homePrm4.dec = Properties.Axis4.Default.dec;
                homePrm4.velHigh = Properties.Axis4.Default.velHigh;
                homePrm4.velLow = Properties.Axis4.Default.velLow;
                homePrm4.smoothTime = Properties.Axis4.Default.Smooth;
                homePrm4.searchHomeDistance = Properties.Axis4.Default.searchhomedistance;
                homePrm4.searchIndexDistance = Properties.Axis4.Default.searchIndexdistance;
                homePrm4.moveDir = 0;
                homePrm4.indexDir = 1;
                homePrm4.triggerIndex = 1;
                homePrm4.homeOffset = Properties.Axis4.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer3()
        {
            try
            {
                homePrm3.mode = 13;
                homePrm3.acc = Properties.Axis3.Default.acc;
                homePrm3.dec = Properties.Axis3.Default.dec;
                homePrm3.velHigh = Properties.Axis3.Default.velHigh;
                homePrm3.velLow = Properties.Axis3.Default.velLow;
                homePrm3.smoothTime = Properties.Axis3.Default.Smooth;
                homePrm3.searchHomeDistance = Properties.Axis3.Default.searchhomedistance;
                homePrm3.searchIndexDistance = Properties.Axis3.Default.searchIndexdistance;
                homePrm3.moveDir = 0;
                homePrm3.indexDir = 1;
                homePrm3.triggerIndex = 1;
                homePrm3.homeOffset = Properties.Axis3.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer2()
        {
            try
            {
                homePrm2.mode = 13;
                homePrm2.acc = Properties.Axis2.Default.acc;
                homePrm2.dec = Properties.Axis2.Default.dec;
                homePrm2.velHigh = Properties.Axis2.Default.velHigh;
                homePrm2.velLow = Properties.Axis2.Default.velLow;
                homePrm2.smoothTime = Properties.Axis2.Default.Smooth;
                homePrm2.searchHomeDistance = Properties.Axis2.Default.searchhomedistance;
                homePrm2.searchIndexDistance = Properties.Axis2.Default.searchIndexdistance;
                homePrm2.moveDir = 0;
                homePrm2.indexDir = 1;
                homePrm2.triggerIndex = 1;
                homePrm2.homeOffset = Properties.Axis2.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void readDataToParamer1()
        {
            try
            {
                homePrm1.mode = 13;
                homePrm1.acc = Properties.Axis1.Default.acc;
                homePrm1.dec = Properties.Axis1.Default.dec;
                homePrm1.velHigh = Properties.Axis1.Default.velHigh;
                homePrm1.velLow = Properties.Axis1.Default.velLow;
                homePrm1.smoothTime = Properties.Axis1.Default.Smooth;
                homePrm1.searchHomeDistance = Properties.Axis1.Default.searchhomedistance;
                homePrm1.searchIndexDistance = Properties.Axis1.Default.searchIndexdistance;
                homePrm1.moveDir = 0;
                homePrm1.indexDir = 1;
                homePrm1.triggerIndex = 1;
                homePrm1.homeOffset = Properties.Axis1.Default.Offset;
            }
            catch (Exception)
            {

                throw;
            }
          
        }
        #endregion
        #region 保存回零参数

        private void SaveUiDataToSetting(int i)
        {
            try
            {

                switch (i)
                {
                    case 1 :
                        SaveUiDataAxis1();
                        break;
                    case 2:
                        SaveUiDataAxis2();
                        break;
                    case 3:
                        SaveUiDataAxis3();
                        break;
                    case 4:
                        SaveUiDataAxis4();
                        break;
                    case 5:
                        SaveUiDataAxis5();
                        break;
                    case 6:
                        SaveUiDataAxis6();
                        break;
                    case 7:
                        SaveUiDataAxis7();
                        break;
                    case 8:
                        SaveUiDataAxis8();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {

               
            }

        }
        private bool SaveUiDataAxis1()
        {
            try
            {

                Properties.Axis1.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis1.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis1.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis1.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis1.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis1.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis1.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis1.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis1.Default.Save();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
               
            }
        }
        private bool SaveUiDataAxis2()
        {
            try
            {

                Properties.Axis2.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis2.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis2.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis2.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis2.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis2.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis2.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis2.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis2.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis3()
        {
            try
            {

                Properties.Axis3.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis3.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis3.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis3.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis3.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis3.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis3.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis3.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis3.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis4()
        {
            try
            {
                Properties.Axis4.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis4.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis4.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis4.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis4.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis4.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis4.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis4.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis4.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis5()
        {
            try
            {
                Properties.Axis5.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis5.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis5.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis5.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis5.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis5.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis5.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis5.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis5.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis6()
        {
            try
            {
                Properties.Axis6.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis6.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis6.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis6.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis6.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis6.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis6.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis6.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis6.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis7()
        {
            try
            {

                Properties.Axis7.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis7.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis7.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis7.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis7.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis7.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis7.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis7.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis7.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        private bool SaveUiDataAxis8()
        {
            try
            {
                Properties.Axis8.Default.velHigh = Convert.ToDouble(this.textBox_velHigh.Text);
                Properties.Axis8.Default.velLow = Convert.ToDouble(this.textBox_velLow.Text);
                Properties.Axis8.Default.acc = Convert.ToDouble(this.textBox_acc.Text);
                Properties.Axis8.Default.dec = Convert.ToDouble(this.textBox_dec.Text);
                Properties.Axis8.Default.Smooth = short.Parse(this.textBox_Smooth.Text);
                Properties.Axis8.Default.Offset = Convert.ToInt32(this.Zero_Offset_tb.Text);
                Properties.Axis8.Default.searchhomedistance = Convert.ToInt32(this.textBox_searchhomedistance.Text);
                Properties.Axis8.Default.searchIndexdistance = Convert.ToInt32(this.textBox_searchIndexdistance.Text);
                Properties.Axis8.Default.Save();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        #endregion

        #region public
        public void backHome()
        {
            //uiDataToPrm();
            for (int i = 1; i < 9; i++)
            {
                readDataToParamer(i);
            }
            // Task Taskgohome = new Task(() => {
            PrintfLog("启动运动");
            Parallel.Invoke(() =>
            {
                MotorsControl.MonitorGoHome(CORE, 3, homePrm3, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 4, homePrm4, homeStatus);
            });
   

            Parallel.Invoke(() =>
            {
                MotorsControl.MonitorGoHome(CORE, 1, homePrm1, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 2, homePrm2, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 3, homePrm3, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 4, homePrm4, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 5, homePrm5, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 6, homePrm6, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 7, homePrm7, homeStatus);
            }, () =>
            {
                MotorsControl.MonitorGoHome(CORE, 8, homePrm8, homeStatus);
            });










            //   });
            //  Taskgohome.Start();
            //for (int i = 1; i < 9; i++)
            //   {
            //    if (i==7 || i==8)
            //    {
            //        MotorsControl.ioSignalEXOMonitoring(CORE, 12, 9, 0);
            //        MotorsControl.ioSignalEXOMonitoring(CORE, 12, 8, 0);
            //    }
            //    if (MotorsControl.MonitorAsyGoHome(CORE, short.Parse(i.ToString()), homePrm1, homeStatus) != 0)
            //    {
            //        PrintfLog(string.Format("回原点错误{0}", i));
            //    };
            //}
        }
        #endregion
        private void Axis_Combox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Axisnum = this.Axis_Combox.SelectedIndex;
            readDataToUI(Axisnum+1);
        }
    }
}
